/**
 * 
 */
package dk.simonvogensen.itodo.tools;

import java.io.File;
import java.io.FileWriter;
import java.io.FilenameFilter;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Date;

import javax.swing.filechooser.FileFilter;

/**
 * @author sbv
 *
 */
public class ManifestBuilder {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		String manifest = "{\n"+
"	// version of the manifest file format\n"+
"	\"betaManifestVersion\": 1,\n"+
"	\n"+
"	// version of the set of resources described in this manifest file\n"+
"	\"version\": \""+new Date().getTime()+"\",\n"+
"	\n"+
"	// URLs to be cached (URLs are given relative to the manifest URL)\n"+
"	\"entries\": [\n";

		File dir = new File("./target/www/dk.simonvogensen.itodo.ITodo/");
		File[] files =  dir.listFiles(new FilenameFilter() {
			public boolean accept(File dir, String name) {
				if("m".equals(name)) return false;
				if("export.php".equals(name)) return false;
				if("data.php".equals(name)) return false;
				if("properties.php".equals(name)) return false;
				if("common.php".equals(name)) return false;
				if("manifest.mf".equals(name)) return false;
				if("test.html".equals(name)) return false;
				if("vim.html".equals(name)) return false;
				return true;
			}
		});
		for (int i = 0; i < files.length; i++) {
			File file = files[i];
			manifest += "		{ \"url\": \""+file.getName()+"\" }";
			if (i < (files.length - 1)) manifest+=",\n"; else manifest+="\n";
		}
		manifest +="	]\n"+
"}\n";
		
		try {
			File fout = new File("./target/www/dk.simonvogensen.itodo.ITodo/manifest.mf");
			PrintWriter out;
			out = new PrintWriter(new FileWriter(fout));
			out.print(manifest);
			out.close();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
}
